package ppjava12v1.chess.chat;

import org.springframework.stereotype.Component;

import javax.websocket.Session;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

@Component
public class ChatroomHolder {

    private Map<String, Session> chatRoom;

    public ChatroomHolder() {
        this.chatRoom = Collections.synchronizedMap(new HashMap<String, Session>());
    }

    public boolean containsNick(String nickname) {
        return chatRoom.containsKey(nickname);
    }

    public Session getSession(String nickname) {
        return chatRoom.get(nickname);
    }

    public Session add(String nickname, Session value) {
        return chatRoom.put(nickname, value);
    }

    public Session remove(String nickname) {
        return chatRoom.remove(nickname);
    }

    public Collection<Session> getAllSessions() {
        return chatRoom.values();
    }
}
